//
//  HMSearchView.swift
//  WeiBo
//
//  Created by 李立达 on 15/12/5.
//  Copyright © 2015年 heima11. All rights reserved.
//

import UIKit

class HMSearchView: UIView,UITextFieldDelegate {

    
    @IBOutlet weak var searchField: UITextField!
    @IBOutlet weak var cachelButton: UIButton!
    @IBOutlet weak var textFiledTrailing: NSLayoutConstraint!

 
    class func searchView() ->HMSearchView {
    
        return NSBundle.mainBundle().loadNibNamed("search", owner: nil, options: nil).last! as! HMSearchView
    }
   
    override init(frame: CGRect) {
        
        super.init(frame: frame)
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
        

    
    @IBAction func CancelClick(sender: UIButton) {
        
        searchField.resignFirstResponder()
        textFiledTrailing.constant = 0
        
        UIView.animateWithDuration(0.5) { () -> Void in
            
            self.searchField.layoutIfNeeded()
        }
       
    }
    
    func textFieldDidBeginEditing(textField: UITextField) {
        
        textFiledTrailing.constant = self.cachelButton.frame.width
        
        UIView.animateWithDuration(0.5) { () -> Void in
            
            self.searchField.layoutIfNeeded()
        }
    }
    
    
}
